package com.dycc.main_componet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dycc.main_componet.R;
import com.dycc.main_componet.adapter.bean.Rc_MixBean;
import com.dycc.main_componet.adapter.bean.Rc_News;
import com.dycc.main_componet.adapter.bean.Rc_OnlyPicBean;
import com.dycc.main_componet.adapter.bean.Rc_VideoBean;
import com.dycc.main_componet.adapter.holder.Rc_NewsMixHolder;
import com.dycc.main_componet.adapter.holder.Rc_NewsThreePicHolder;
import com.dycc.main_componet.adapter.holder.Rc_NewsVideoHolder;

import java.util.List;

/**
 * Created by Administrator on 2018/1/26 0026.
 */

public class Rc_NewsAdapter extends BaseMultiItemQuickAdapter<Rc_News, BaseViewHolder> {
    LayoutInflater inflater;
    Context context;

    public Rc_NewsAdapter(List<Rc_News> data, Context context) {
        super(data);
        inflater = LayoutInflater.from(context);

        this.context = context;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case Rc_News.NEWS_MIX:
                return new Rc_NewsMixHolder(inflater.inflate(R.layout.adapter_rc_mix_item, parent, false));
            case Rc_News.NEWS_ONLYPIC:
                return new Rc_NewsThreePicHolder(inflater.inflate(R.layout.adapter_rc_threepic_item, parent, false));
            case Rc_News.NEWS_VIDEO:
                return new Rc_NewsVideoHolder(inflater.inflate(R.layout.adapter_rc_video_item, parent, false));
        }

        return super.onCreateViewHolder(parent, viewType);
    }


    @Override
    protected void convert(BaseViewHolder helper, Rc_News item) {
        switch (item.getItemType()) {
            case Rc_News.NEWS_MIX:
                if (helper instanceof Rc_NewsMixHolder && item.getT() instanceof Rc_MixBean) {
                    try {
                    Glide.with(context).load(((Rc_MixBean) item.getT()).getPics().get(0).getUrl())
                            .placeholder(R.drawable.pic_defaultholder)
                            .into((((Rc_NewsMixHolder) helper).getRcMixImageitemIcon()));
                    }catch (Exception ex){}
                }
                break;
            case Rc_News.NEWS_ONLYPIC:
                if (helper instanceof Rc_NewsThreePicHolder&&item.getT() instanceof Rc_OnlyPicBean) {
                    try {
                        Glide.with(context).load(((Rc_OnlyPicBean) item.getT()).getPics().get(0).getUrl())
                                .placeholder(R.drawable.pic_defaultholder)
                                .into((((Rc_NewsThreePicHolder) helper).getRcThreepicImageitemFirst()));
                        Glide.with(context).load(((Rc_OnlyPicBean) item.getT()).getPics().get(1).getUrl())
                                .placeholder(R.drawable.pic_defaultholder)
                                .into((((Rc_NewsThreePicHolder) helper).getRcThreepicImageitemSecond()));
                        Glide.with(context).load(((Rc_OnlyPicBean) item.getT()).getPics().get(2).getUrl())
                                .placeholder(R.drawable.pic_defaultholder)
                                .into((((Rc_NewsThreePicHolder) helper).getRcThreepicImageitemThree()));
                    }catch (Exception ex){
                    }
                }
                break;
            case Rc_News.NEWS_VIDEO:
                if (helper instanceof Rc_NewsVideoHolder&&item.getT() instanceof Rc_VideoBean) {
                    try {
                        ((Rc_NewsVideoHolder)helper) .getRcVideoPlayerItem().setUp(((Rc_VideoBean)item.getT())
                                .getVideoUrl(),((Rc_VideoBean)item.getT()).getTitle());
                        Glide.with(context).load(((Rc_VideoBean)item.getT()).getIcon()).into(
                                ((Rc_NewsVideoHolder)helper) .getRcVideoPlayerItem().ivThumb);
                    }catch (Exception ex){
                    }
                }
                break;
            default:
                break;
        }
    }
}
